package com.heima.wemedia.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class ThreadPoolConfig {

    @Bean(name = "ThreadPool")
    public ThreadPoolTaskExecutor taskExecutor() {
        //线程池配置
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(4); // 核心线程数
        executor.setMaxPoolSize(8); // 最大线程数
        executor.setQueueCapacity(8); // 队列容量
        executor.setThreadNamePrefix("ThreadPool-"); // 线程名称前缀
        executor.initialize(); // 初始化线程池
        return executor;
    }
}